package com.ai.controller.bt;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.ai.common.controller.BaseController;
import com.ai.common.core.enums.ImgTypes;
import com.ai.common.model.Pagination;
import com.ai.common.model.Result;
import com.ai.mmd.reviewed.dto.QyzhDTO;
import com.ai.mmd.reviewed.dto.SbhzinfoDTO;
import com.ai.mmd.reviewed.dto.SbhzinfoExtDTO;
import com.ai.mmd.reviewed.dto.SbmxinfoDTO;
import com.ai.mmd.reviewed.vo.SbhzinfoVO;
import com.ai.mmd.reviewed.vo.SbmxinfoExtVO;
import com.ai.mmd.system.dto.GkinfoDTO;
import com.ai.mmd.system.dto.HwlxinfoDTO;
import com.ai.mmd.system.dto.SbsjinfoDTO;
import com.ai.mmd.system.dto.XxinfoDTO;
import com.ai.mmd.system.dto.ZdinfoDTO;
import com.ai.model.member.info.dto.DataTablesDto;
import com.ai.service.reviewed.model.QyzhModel;
import com.ai.service.reviewed.model.SbhzinfoModel;
import com.ai.service.reviewed.model.SbmxinfoModel;
import com.ai.service.reviewed.model.YhxxModel;
import com.ai.service.reviewed.service.IQyzhService;
import com.ai.service.reviewed.service.ISbhzinfoService;
import com.ai.service.reviewed.service.ISbmxinfoService;
import com.ai.service.system.model.BtbzinfoModel;
import com.ai.service.system.model.GkinfoModel;
import com.ai.service.system.model.HwlxinfoModel;
import com.ai.service.system.model.SbsjinfoModel;
import com.ai.service.system.model.XxinfoModel;
import com.ai.service.system.model.ZdinfoModel;
import com.ai.service.system.service.IBtbzinfoService;
import com.ai.service.system.service.IGkinfoService;
import com.ai.service.system.service.IHwlxinfoService;
import com.ai.service.system.service.ISbsjinfoService;
import com.ai.service.system.service.IXxinfoService;
import com.ai.service.system.service.IZdinfoService;
import com.ai.view.GkViewExcel;
import com.ai.view.SldataViewExcel;
import com.ai.view.ZdViewExcel;

import freemarker.template.Configuration;
import freemarker.template.Template;

@RequestMapping("/btsb")
@Controller("com.ai.controller.bt.SbhzController")
public class SbhzController extends BaseController{
	
	@Value("${mainDomainPre}")
	private String mainDomainPre;
	
	/**
	 * Description ：补贴申报页面索引
	 */
	@RequestMapping("/addhzindex")
	public String addhzindex()throws Exception {
		
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null) {
			return "/front/frontgoods/login";
		}
		
		Result result = new Result(true);
		
		//获得当前年份和季度
		Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int currentyear = year;
        int currentMonth = c.get(Calendar.MONTH) + 1;
        int lastQuarter = 0;
        if (currentMonth >= 1 && currentMonth <= 3){
        	lastQuarter = 4;
        	year = year - 1;
        }else if (currentMonth >= 4 && currentMonth <= 6)
        	lastQuarter = 1;
        else if (currentMonth >= 7 && currentMonth <= 9)
        	lastQuarter = 2;
        else if (currentMonth >= 10 && currentMonth <= 12)
        	lastQuarter = 3;
        
        //获得申报截止时间
        SbsjinfoDTO sbsjinfoDTO = new SbsjinfoDTO();
        if (lastQuarter==4) {
        	sbsjinfoDTO.setJd(1);
		} else {
			sbsjinfoDTO.setJd(lastQuarter+1);
		}
        SbsjinfoModel sbsjinfoModel = isbsjinfoService.getOne(sbsjinfoDTO);
        String sbsj = String.valueOf(currentyear)+"-"+addZero(currentMonth)+"-"+addZero(sbsjinfoModel.getSbsj());
        
        //存入集合
        result.addAttribute("sbsj", sbsj);
        result.addAttribute("dqnf", year);
        result.addAttribute("dqjd", lastQuarter);
        result.rendering();
		
		return "/front/frontgoods/btsb/addsb";
	}
	
	/**
	 * 下载箱量核对模版Excel
	 * 
	 * @return
	 */
	@RequestMapping("/export/xlhdExcelView")
	public ModelAndView xlhdExcelView() throws Exception {
		XxinfoDTO xxinfoDTO = new XxinfoDTO();
		GkinfoDTO gkinfoDTO = new GkinfoDTO();
		ZdinfoDTO zdinfoDTO = new ZdinfoDTO();
		HwlxinfoDTO hwlxinfoDTO = new HwlxinfoDTO();
		xxinfoDTO.setSfsc(0);
		gkinfoDTO.setSfsc(0);
		zdinfoDTO.setSfsc(0);
		hwlxinfoDTO.setSfsc(0);
		List<XxinfoModel> xxlist = ixxinfoService.getList(xxinfoDTO);
		List<GkinfoModel> gklist = igkinfoService.getList(gkinfoDTO);
		List<ZdinfoModel> zdlist = izdinfoService.getList(zdinfoDTO);
		List<HwlxinfoModel> hwlxlist = ihwlxinfoService.getList(hwlxinfoDTO);
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("xxlist", xxlist);
		model.put("gklist", gklist);
		model.put("zdlist", zdlist);
		model.put("hwlxlist", hwlxlist);
		return new ModelAndView(new SldataViewExcel(), model);
	}
	
	/**
	 * Description ：添加补贴申报
	 */
	@RequestMapping(value = "/addhzandmx", method = { RequestMethod.POST, RequestMethod.GET })   
    public void addhzandmx(@RequestParam(value = "hdxxfile") MultipartFile file,   HttpServletRequest request,
    		@ModelAttribute SbhzinfoDTO sbhzinfoDTO) throws Exception {    
		        
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null) {
			return;
		}
		
		String message = "";
		response.setContentType("text/html;charset=utf-8");
		
		//判断是否重复申报
		sbhzinfoDTO.setYhid(yhxxModel.getYhid());
		SbhzinfoModel sbhzinfoModel = isbhzinfoService.getOne(sbhzinfoDTO);
		if (sbhzinfoModel!=null&&sbhzinfoModel.getHzzt()!=0&&sbhzinfoModel.getHzzt()!=4) {
			message = "该季度已经发起申请";
			response.getWriter().write("{\"message\":\""+ message +"\"}");
			return;
		}
		
		if (sbhzinfoModel!=null) {
			sbhzinfoDTO.setHzdh(sbhzinfoModel.getHzdh());
		}
		
		sbhzinfoDTO.setTbsj(new Date());
		
		Map<String, String> map = new HashMap<String, String>();
		if(file.getOriginalFilename().toLowerCase().endsWith("xls")){
			map = isbmxinfoService.readXls(file.getInputStream(),sbhzinfoDTO);
        }else{
        	map = isbmxinfoService.readXlsx(file.getInputStream(),sbhzinfoDTO);
        }
	    message = map.get("nret");
		String hzdh = map.get("hzdh");
		
		if ("0".equals(message)) {
			session.setAttribute("dh", hzdh);
			response.getWriter().write("{\"message\":\"Y\"}");
		}else {
			response.getWriter().write("{\"message\":\""+ message +"\"}");
		}
    }
	
	/**
	 * 列表
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("hzlist")
	public DataTablesDto<SbhzinfoVO> list(@ModelAttribute SbhzinfoDTO sbhzinfoDTO,@RequestParam(defaultValue = "0") Integer start)
			throws Exception {
		DataTablesDto<SbhzinfoVO> dto = new DataTablesDto<SbhzinfoVO>();
		
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null) {
			return dto;
		}
		
		int rows = 10;
		int page = (start / rows)+1;
		sbhzinfoDTO.setPage(page);
		sbhzinfoDTO.setRows(rows);
		sbhzinfoDTO.setYhid(yhxxModel.getYhid());
		
		Pagination<SbhzinfoVO> list = isbhzinfoService.getListVO(sbhzinfoDTO);
		dto.setRowsData(list.getRows());
		dto.setiTotalRecords(list.getTotal());
		dto.setiTotalDisplayRecords(list.getTotal());
		return dto;
	}
	
	/**
	 * Description ：补贴申报列表索引
	 */
	@RequestMapping("/hzlistindex")
	public String hzlistindex() {
		
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null) {
			return "/front/frontgoods/login";
		}
		
		return "/front/frontgoods/btsb/btsqhzlist";
	}
	
	/**
	 * 发布补贴申请
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("publish")
	public Map<String, Object> publish(@ModelAttribute SbhzinfoDTO sbhzinfoDTO)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
			
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null||sbhzinfoDTO.getId()==null) {
			return map;
		}
		
		SbmxinfoDTO sbmxinfoDTO = new SbmxinfoDTO();
		
		//循环遍历明细图片是否存在
		SbhzinfoModel sbhzinfoModel = isbhzinfoService.getByPrimaryKey(sbhzinfoDTO.getId());
		sbmxinfoDTO.setHzdh(sbhzinfoModel.getHzdh());
		List<SbmxinfoModel> list = isbmxinfoService.getList(sbmxinfoDTO);
		File file = null; 
		for (SbmxinfoModel sbmxinfoModel : list) {
			Boolean isMarch = false;
			//铁路图片验证
			for (String imgType : ImgTypes.imgTypeList) {	
				file = new File(mainDomainPre+yhxxModel.getYhid()+"/"+ sbhzinfoModel.getSbnf() + sbhzinfoModel.getSbjd() + "/" +sbmxinfoModel.getTlzpmc()+"."+imgType);
				if (file.exists()) {
					isMarch = true;
					break;
				}
			}
			if (!isMarch) {
				map.put("status", -1);
				map.put("errormsg", "铁路图片存在没上传的图片!");
				map.put("errordata", sbmxinfoModel.getTlzpmc());
				return map;
			}else {
				isMarch = false;
			}
			
			//水路图片验证
			for (String imgType : ImgTypes.imgTypeList) {
				file = new File(mainDomainPre+yhxxModel.getYhid()+"/" + sbhzinfoModel.getSbnf() + sbhzinfoModel.getSbjd() + "/" +sbmxinfoModel.getSlzpmc()+"."+imgType);
				if (file.exists()) {
					isMarch = true;
					break;
				}
			}
			if (!isMarch) {
				map.put("status", -2);
				map.put("errormsg", "水路图片存在没上传的图片!");
				map.put("errordata", sbmxinfoModel.getSlzpmc());
				return map;
			}else {
				isMarch = false;
			}
			
			if (sbmxinfoModel.getMylx()==2) {
				//海关图片验证
				for (String imgType : ImgTypes.imgTypeList) {
					file = new File(mainDomainPre+yhxxModel.getYhid()+"/" + sbhzinfoModel.getSbnf() + sbhzinfoModel.getSbjd() + "/" +sbmxinfoModel.getHgzpmc()+"."+imgType);
					if (file.exists()) {
						isMarch = true;
						break;
					}
				}
				if (!isMarch) {
					map.put("status", -3);
					map.put("errormsg", "海关图片存在没上传的图片!");
					map.put("errordata", sbmxinfoModel.getSlzpmc());
					return map;
				}else {
					isMarch = false;
				}
			}
		}
		
		//判断单据是否全部上传
//		sbmxinfoDTO.setYhid(yhxxModel.getYhid());
//		sbmxinfoDTO.setSfsc(0);
//		sbmxinfoDTO.setSbnf(sbhzinfoDTO.getSbnf());
//		sbmxinfoDTO.setSbjd(sbhzinfoDTO.getSbjd());
//		List<SbmxinfoModel> hwydhlist = isbmxinfoService.getUnbindhwydhList(sbmxinfoDTO);
//		List<SbmxinfoModel> tlhphlist = isbmxinfoService.getUnbindtlhphList(sbmxinfoDTO);
//		List<SbmxinfoModel> hgsbdlist = isbmxinfoService.getUnbindhgsbList(sbmxinfoDTO);
//		if (hwydhlist.size()>0) {
//			map.put("status", -1);
//			map.put("errormsg", "水路运单存在没上传的单据!");
//			map.put("errordata", hwydhlist.get(0).getHwydh());
//			return map;
//		}
//		if (tlhphlist.size()>0) {
//			map.put("status", -2);
//			map.put("errormsg", "铁路货票存在没上传的单据!");
//			map.put("errordata", tlhphlist.get(0).getTlhph());
//			return map;
//		}
//		if (hgsbdlist.size()>0) {
//			map.put("status", -3);
//			map.put("errormsg", "海关申报单存在没上传的单据!");
//			map.put("errordata", hgsbdlist.get(0).getHgsbdh());
//			return map;
//		}
		
		sbhzinfoDTO.setHzzt(5);
		sbhzinfoDTO.setGxsj(new Date());
		SbhzinfoModel upsbhzinfoModel = new SbhzinfoModel();
		BeanUtils.copyProperties(sbhzinfoDTO, upsbhzinfoModel);
		isbhzinfoService.updateMxBatch(upsbhzinfoModel, 0);
		
		map.put("status", 0);
		
		return map;
	}
	
	/**
	 * Description ：本次补贴申报列表索引
	 */
	@RequestMapping("/onehzlistindex")
	public String onehzlistindex() {
		
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null) {
			return "/front/frontgoods/login";
		}
		
		return "/front/frontgoods/btsb/onebtsqhzlist";
	}
	
	/**
	 * 本次列表
	 * @param gkinfoDTO
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("onehzlist")
	public DataTablesDto<SbhzinfoVO> onehzlist(@ModelAttribute SbhzinfoDTO sbhzinfoDTO)
			throws Exception {
		DataTablesDto<SbhzinfoVO> dto = new DataTablesDto<SbhzinfoVO>();
		
		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel==null) {
			List<SbhzinfoVO> list = new ArrayList<SbhzinfoVO>();
			dto.setRowsData(list);
			dto.setiTotalRecords(list.size());
			dto.setiTotalDisplayRecords(list.size());
			return dto;
		}
		
		Object hzdh = request.getSession().getAttribute("dh");
		if (hzdh!=null) {
			sbhzinfoDTO.setHzdh(hzdh.toString());
		}else {
			List<SbhzinfoVO> list = new ArrayList<SbhzinfoVO>();
			dto.setRowsData(list);
			dto.setiTotalRecords(list.size());
			dto.setiTotalDisplayRecords(list.size());
			return dto;
		}
			
		sbhzinfoDTO.setYhid(yhxxModel.getYhid());
		
		Pagination<SbhzinfoVO> list = isbhzinfoService.getListVO(sbhzinfoDTO);
		dto.setRowsData(list.getRows());
		dto.setiTotalRecords(list.getTotal());
		dto.setiTotalDisplayRecords(list.getTotal());
		return dto;
	}
	
	/**
	 * 导出港口集装箱出入闸记录Excel
	 * 
	 * @return
	 */
	@RequestMapping("/export/gkExcelView")
	public ModelAndView gkExcelView(@ModelAttribute SbhzinfoExtDTO sbhzinfoExtDTO) throws Exception {

		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel!=null) {
			sbhzinfoExtDTO.setYhid(yhxxModel.getYhid());
		}
		
		//武汉
		sbhzinfoExtDTO.setGklx(2);
		List<SbmxinfoExtVO> gkwh = isbhzinfoService.getsbgkList(sbhzinfoExtDTO);
		//阳逻
		sbhzinfoExtDTO.setGklx(3);
		List<SbmxinfoExtVO> gkyl = isbhzinfoService.getsbgkList(sbhzinfoExtDTO);
		//阳逻一期
		sbhzinfoExtDTO.setGklx(44);
		List<SbmxinfoExtVO> gkfirst = isbhzinfoService.getsbgkList(sbhzinfoExtDTO);
		//阳逻二期
		sbhzinfoExtDTO.setGklx(45);
		List<SbmxinfoExtVO> gksecond = isbhzinfoService.getsbgkList(sbhzinfoExtDTO);
		//阳逻三期
		sbhzinfoExtDTO.setGklx(46);
		List<SbmxinfoExtVO> gkthirth = isbhzinfoService.getsbgkList(sbhzinfoExtDTO);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("gkwh", gkwh);
		model.put("gkyl", gkyl);
		model.put("gkfirst", gkfirst);
		model.put("gksecond", gksecond);
		model.put("gkthirth", gkthirth);
		
		return new ModelAndView(new GkViewExcel(), model);
	}
	
	/**
	 * 导出站点集装箱出入闸记录Excel
	 * 
	 * @return
	 */
	@RequestMapping("/export/zdExcelView")
	public ModelAndView zdExcelView(@ModelAttribute SbhzinfoExtDTO sbhzinfoExtDTO) throws Exception {

		YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
		if (yhxxModel!=null) {
			sbhzinfoExtDTO.setYhid(yhxxModel.getYhid());
		}
		
		//吴家山
		sbhzinfoExtDTO.setZdlx(1);
		List<SbmxinfoExtVO> zdwjs = isbhzinfoService.getsbzdList(sbhzinfoExtDTO);
		
		//滠口
		sbhzinfoExtDTO.setZdlx(9);
		List<SbmxinfoExtVO> zdsk = isbhzinfoService.getsbzdList(sbhzinfoExtDTO);
		
		Map<String, Object> model = new HashMap<String, Object>();
		model.put("zdwjs", zdwjs);
		model.put("zdsk", zdsk);
		
		return new ModelAndView(new ZdViewExcel(), model);
	}
	
	/**
	 * 下载贴水联运申请单
	 * 
	 * @date 2016年6月26日 下午3:23:10
	 * @param gshysInfoDTO
	 * @return
	 * @throws Exception
	 *             Pagination<GshysInfoModel>
	 */
	@RequestMapping(value = "/downtslysqd")
	public void downtslysqd(@ModelAttribute SbhzinfoDTO sbhzinfoDTOPara) throws Exception {
		
		request.setCharacterEncoding("utf-8");  
        Map<String, Object> map = new HashMap<String, Object>(); 
        //获得最近一次申报成功的信息
        
        //1.获取用户信息
        YhxxModel yhxxModel = (YhxxModel)request.getSession().getAttribute("yhxxModel");
        String qyqc = yhxxModel.getQyqc();
        QyzhDTO qyzhDTO = new QyzhDTO();
        qyzhDTO.setYhid(yhxxModel.getYhid());
        QyzhModel qyzhModel = iqyzhService.getOne(qyzhDTO);
        String qyzh = "";
        if (qyzhModel!=null) {
        	qyzh = qyzhModel.getKhh() + " " + qyzhModel.getZhkh();
		}
        
        //2.获取补贴标准
        BtbzinfoModel btbzinfoModel = ibtbzinfoService.getByPrimaryKey(1);
        Integer btbz = 0;
        if (btbzinfoModel!=null) {
        	btbz = btbzinfoModel.getCash();
		}
        
        //3.获取最近申报的时间段
        String sjd = "";
        Integer xl = 0;
        Integer cash = 0;
        SbhzinfoDTO sbhzinfoDTO = new SbhzinfoDTO();
        sbhzinfoDTO.setHzzt(3);
        sbhzinfoDTO.setYhid(yhxxModel.getYhid());
        sbhzinfoDTO.setSort("sbnf,sbjd desc");
        sbhzinfoDTO.setRows(1);
        sbhzinfoDTO.setSbnf(sbhzinfoDTOPara.getSbnf());
        sbhzinfoDTO.setSbjd(sbhzinfoDTOPara.getSbjd());
        SbhzinfoModel sbhzinfoModel = isbhzinfoService.getOne(sbhzinfoDTO);
        if (sbhzinfoModel!=null) {
        	sjd = sbhzinfoModel.getSbnf() + "年第" + sbhzinfoModel.getSbjd() + "季度";
        	xl = sbhzinfoModel.getZxl();
        	cash = sbhzinfoModel.getBtje();
		}
        
        //将参数放入键值对映射中
        map.put("qyqc", qyqc);
        map.put("qyzh", qyzh);
        map.put("xl", xl.toString() + "TEU");
        map.put("cash", Float.parseFloat(cash.toString())/10000);
        map.put("btbz", btbz.toString() + "元/TEU");
        map.put("sjd", sjd);
        
        // 提示：在调用工具类生成Word文档之前应当检查所有字段是否完整  
        // 否则Freemarker的模板殷勤在处理时可能会因为找不到值而报错 这里暂时忽略这个步骤了  
        File file = null;  
        InputStream fin = null;  
        ServletOutputStream out = null;  
        try {  
            // 调用工具类WordGenerator的createDoc方法生成Word文档  
            file = createDoc(map, "tslysqb");  
            fin = new FileInputStream(file);  
              
            response.setCharacterEncoding("utf-8");  
            response.setContentType("application/msword");  
            // 设置浏览器以下载的方式处理该文件默认名为resume.doc  
            response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("武汉集装箱铁水联运专项补贴资金申请表.doc", "UTF-8"));  
              
            out = response.getOutputStream();  
            byte[] buffer = new byte[512];  // 缓冲区  
            int bytesToRead = -1;  
            // 通过循环将读入的Word文件的内容输出到浏览器中  
            while((bytesToRead = fin.read(buffer)) != -1) {  
                out.write(buffer, 0, bytesToRead);  
            }  
        } finally {  
            if(fin != null) fin.close();  
            if(out != null) out.close();  
            if(file != null) file.delete(); // 删除临时文件  
        }  
	}
	
	private Configuration configuration = null;  
    private Map<String, Template> allTemplates = null; 
	
	private File createDoc(Map<?, ?> dataMap, String type) { 
		
		configuration = new Configuration();  
        configuration.setDefaultEncoding("utf-8");  
        allTemplates = new HashMap<String, Template>();
        String baseFolder = this.getClass().getClassLoader()
				.getResource("../../upload/template").getPath();
        try {
        	configuration.setDirectoryForTemplateLoading(new File(baseFolder));
            allTemplates.put("tslysqb", configuration.getTemplate("tslysqb.ftl"));  
        } catch (IOException e) {  
            e.printStackTrace();  
            throw new RuntimeException(e);  
        }  
		
        String name = "temp" + (int) (Math.random() * 100000) + ".doc";  
        File f = new File(name);  
        Template t = allTemplates.get(type);  
        try {  
            // 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开  
            Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8");  
            t.process(dataMap, w);  
            w.close();  
        } catch (Exception ex) {  
            ex.printStackTrace();  
            throw new RuntimeException(ex);  
        }  
        return f;  
    }
	
	/**
	 * Description ：补贴申报页面索引
	 */
	@RequestMapping("/btsqxz")
	public String btsqxz() {
		
		return "/front/frontgoods/btsb/sqrepotlist";
	}
	
	private String addZero(Integer num) {
		 return num < 10 ? "0"+String.valueOf(num): String.valueOf(num);
	}
	
	@Resource(name = "isbhzinfoService")
	private ISbhzinfoService isbhzinfoService;
	
	@Resource(name = "isbmxinfoService")
	private ISbmxinfoService isbmxinfoService;
	
	@Resource(name = "ixxinfoService")
	private IXxinfoService ixxinfoService;
	
	@Resource(name = "igkinfoService")
	private IGkinfoService igkinfoService;
	
	@Resource(name = "izdinfoService")
	private IZdinfoService izdinfoService;
	
	@Resource(name = "ihwlxinfoService")
	private IHwlxinfoService ihwlxinfoService;
	
	@Resource(name = "iqyzhService")
	private IQyzhService iqyzhService;
	
	@Resource(name = "ibtbzinfoService")
	private IBtbzinfoService ibtbzinfoService;
	
	@Resource(name = "isbsjinfoService")
	private ISbsjinfoService isbsjinfoService;
}
